package com.home.zqt.platform.configure;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;

/**
 * @author soon
 * @description: TODO
 * @date 2019-06-01 12:10
 **/
@Configuration
public class DataSourceConfig {

    /**
     * 生产环境数据源
     *
     * @param env
     * @return
     */
    @Bean(name = "productDs")
    public DataSource dataSourceProduct(Environment env) {
        HikariDataSource ds = new HikariDataSource();
        ds.setJdbcUrl(env.getProperty("spring.datasource.product.url"));
        ds.setUsername(env.getProperty("spring.datasource.product.username"));
        ds.setPassword(env.getProperty("spring.datasource.product.password"));
        ds.setDriverClassName(env.getProperty("spring.datasource.product.driver-class-name"));
        return ds;
    }

    /**
     * 预发布环境数据源
     *
     * @param env
     * @return
     */
    @Bean(name = "prepareDs")
    public DataSource dataSourcePrepare(Environment env) {
        HikariDataSource ds = new HikariDataSource();
        ds.setJdbcUrl(env.getProperty("spring.datasource.prepare.url"));
        ds.setUsername(env.getProperty("spring.datasource.prepare.username"));
        ds.setPassword(env.getProperty("spring.datasource.prepare.password"));
        ds.setDriverClassName(env.getProperty("spring.datasource.prepare.driver-class-name"));
        return ds;
    }

    /**
     * 日常环境数据源
     *
     * @param env
     * @return
     */
    @Bean(name = "dailyDs")
    public DataSource dataSourceDaily(Environment env) {
        HikariDataSource ds = new HikariDataSource();
        ds.setJdbcUrl(env.getProperty("spring.datasource.daily.url"));
        ds.setUsername(env.getProperty("spring.datasource.daily.username"));
        ds.setPassword(env.getProperty("spring.datasource.daily.password"));
        ds.setDriverClassName(env.getProperty("spring.datasource.daily.driver-class-name"));
        return ds;
    }
}
